<?php
/*
 * @Author: lokei
 * @Date: 2022-11-14 11:23:24
 * @LastEditors: lokei
 * @LastEditTime: 2022-11-14 15:18:13
 * @Description: 
 */
namespace App\Http\Controllers\Order\Delivery;

use App\Common\Tools\ResultTool;
use App\Http\Controllers\Controller;
use App\Models\Order\Delivery\CompanyModel;
use App\Models\Order\Delivery\DeliveryModel;
use Illuminate\Http\Request;

class DeliveryController extends Controller {
    public function ofOrder(Request $request) {
        $items = DeliveryModel::where('order_id', '=', $request->input('order_id'))->get();
        $res = ResultTool::success();
        $res['data']['items'] = $items;
        $res['data']['total'] = count($items);
        return $res;
    }

    public function submit(Request $request) {
        $delivery = new DeliveryModel();
        $delivery->order_id = $request->input('order_id');
        $delivery_company = CompanyModel::where('id', '=', $request->input('delivery_company_id'))->first();
        $delivery->delivery_company_name = $delivery_company->name;
        $delivery->delivery_company_id = $request->input('delivery_company_id');
        $delivery->delivery_sn = $request->input('delivery_sn');
        $delivery->note = $request->input('note');
        $delivery->created_at = date('Y-m-d H:i:s', time());
        $delivery->status = '0';
        $delivery->save();
        return ResultTool::success();
    }
}